<?php

namespace app\common\model\jooj_member;

/**
 * Description of MemberFamilys
 * jj_member_familys_1
 * @author tommy.pan
 */
class MemberFamilys extends Base {

    protected $base_table = 'jj_member_familys';
    protected $table = 'jj_member_familys';
    protected $connection = ['database' => 'jooj_member'];

    /**
     * 初始化方法
     * @param type $companyId
     */
    public function __construct($companyId = []) {
        if (!is_array($companyId)) {
            $this->table = $this->base_table . '_' . $companyId;
        }
        parent::__construct($companyId);
    }

    /**
     * 获取列表
     * @param type $condition
     * @param type $field
     * @return type
     */
    public function getListByCondition($condition, $field) {
        return $this->field($field)->where($condition)->select();
    }

    /**
     * 增加关系绑定
     * @param type $data
     * @return type
     */
    public function addMemberFamily($data) {
        $save = $this->data($data)->save();
        return $save;
    }

    /**
     * 删除家庭关系
     * @param type $id
     * @return type
     */
    public function removeFamilyRelation($id) {
        $delete = $this->where(['family_id' => $id])->delete();
        return $delete;
    }

    /**
     * 获取家庭信息
     * @param type $id
     * @return type obj
     */
    public function getFamilyInfoById($id) {
        $info = $this->where(['family_id' => $id])->find();
        return $info;
    }

}
